import { PeriodTaskApiService } from './../../../api/period-task-api.service';
import { NzMessageService } from 'ng-zorro-antd/message';
import { PeroidicTaskAdderComponent } from './../peroidic-task-adder/peroidic-task-adder.component';
import { Component, OnInit, ViewChild } from '@angular/core';

@Component({
  selector: 'app-peroidic-task-add-page',
  templateUrl: './peroidic-task-add-page.component.html',
  styleUrls: ['./peroidic-task-add-page.component.less']
})
export class PeroidicTaskAddPageComponent implements OnInit {
  @ViewChild('taskAdder') taskAdder?: PeroidicTaskAdderComponent;
  constructor(
    private msg: NzMessageService,
    private api: PeriodTaskApiService,
  ) { }

  ngOnInit(): void {
  }

  submit(): void {
    const submitData = this.taskAdder?.getData();
    console.log(submitData);

    if (submitData) {
      this.api.create(submitData).subscribe(
        reponse => {
          this.msg.success('创建工作成功!');
          setTimeout(this.cancle, 500);
        },
        err => {
          this.msg.error('创建工作错误！');
          console.error('创建工作错误！', err);
        }
      );
    }
  }

  cancle = (): void => {
    this.taskAdder?.reset();
  }

}
